﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebService
{
    /// <summary>
    /// Summary description for SapWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class SapWebService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public decimal GetAtp(string key, string productCode, string plantCode)
        {
            //Random number 0 - 3000
            //return new Random().Next(3001);

            return 3000;
        }

        [WebMethod]
        public DataTable GetAtpData(string productCode)
        {
            string[] plants = { "2811", "2813", "2547", "2555" };
            string[] dtColumns = { "Materialno", "Plant", "StorageLocation", "URQty", "UIQty", "BlackedQty", "ATPQty" };
            DataTable dt = new DataTable("productAtp");

            foreach (var column in dtColumns)
            {
                dt.Columns.Add(column);
            }

            var r1 = new Random();
            var r2 = new Random();
            var r3 = new Random();
            var r4 = new Random();
            foreach (var plant in plants)
            {
                
                dt.Rows.Add(new object[] { productCode, plant, "SB", r1.Next(500), r2.Next(100), r3.Next(1000), r4.Next(10000) });
            }
            return dt;
        }
    }
}
